<template>
	<view class="content">
		<view class="gongy">
			<text class="title_g">私钥</text>
			<view class="gong_txt">
				<u--textarea class="textarea" ref="privateKey" v-model="passwordForm.private_key" placeholder="请粘贴您的公钥以-----BEGIN PUBLIC KEY----开始,以-----ENDPUBLICKEY-----结束" border="none"></u--textarea>
			</view>
		</view>
		<view class="gongy">
			<text class="title_g">公钥</text>
			<view class="gong_txt">
				<u--textarea class="textarea" ref="publicKey" v-model="passwordForm.public_key" placeholder="请粘贴您的公钥以-----BEGIN PUBLIC KEY----开始,以-----ENDPUBLICKEY-----结束" border="none"></u--textarea>
			</view>
		</view>
		<view class="gongy">
			<text class="title_g">钱包地址</text>
			<view class="gong_txt">
				<u--textarea class="textarea" ref="usdtAddress" v-model="passwordForm.usdt_address" placeholder="请粘贴您的公钥以-----BEGIN PUBLIC KEY----开始,以-----ENDPUBLICKEY-----结束" border="none" style="height: 110rpx;"></u--textarea>
			</view>
		</view>
		
		<view>
			<u-button type="primary" class="login_btnd" color="#53c393" :plain="true" text="一键备份" @click="relywalletClick" style="margin-top: 50rpx;"></u-button>
			<u-button type="primary" color="#53c393" text="开始接单" @click="StartClick" v-if="type == 'login' || isStart" style="margin-top: 10rpx;"></u-button>
			<u-button type="primary" color="#c05c5e" text="退出登录" :plain="true" @click="ExitClick" v-if="type == 'exit'" style="margin-top: 10rpx;"></u-button>
		</view>
		
		<u-modal :show="confirmShow" :showCancelButton="true" @cancel="confirmCancel" @confirm="confirmClick" confirmText="我已保存" cancelText="考虑一下">
			<view class="slot-content">
				<rich-text :nodes="content">
					<img src="../../static/common/warning_icon.png" alt="">
				</rich-text>
			</view>
		</u-modal>
		<u-modal :show="copyShow" @confirm="copyClick" confirmText="我知道了">
			<view class="slot-content">
				<rich-text :nodes="content">
					<img src="../../static/common/warning_icon.png" alt="">
				</rich-text>
			</view>
		</u-modal>
		
		<botLine />
	</view>
</template>

<script>
	import botLine from '../../components/botLine.vue'
	export default {
		components:{
			botLine
		},
		data() {
			return {
				type : 'login',
				passwordForm:{},
				isStart:true,
				content:'<img src="../../static/common/warning_icon.png" alt="" style="width:72px;height:72px;display:block;margin:0 auto;"><br/>请确认您已经将密钥和钱包地址保存到安全的地方，以免丢失',
				confirmShow:false,
				content:'<img src="../../static/common/success_icon.png" alt="" style="width:72px;height:72px;display:block;margin:0 auto;"><br/>复制成功，请将钱包信息粘贴到安全的地方进行备份',
				copyShow : false
			}
		},
		onLoad() {
			this.type = this.$route.query.type;
			this.passwordForm = JSON.parse(sessionStorage.getItem('passwordForm'))
			uni.request({
				url:'/index/api/get_addressinfo',
				method:'post',
				data:this.passwordForm,
				success:res=>{
					if(res.data.status == 200){
						this.passwordForm.private_key = res.data.info.private_key;
						this.passwordForm.public_key = res.data.info.public_key;
						this.passwordForm.usdt_address = res.data.info.usdt_address;
						
						console.log(this.passwordForm)
						uni.request({
							url:'/index/api/reg_user',
							method:'post',
							data:this.passwordForm,
							success:res=>{
								console.log(res.data);
								if(res.data.info){this.isStart = false}else{this.isStart = true}
								localStorage.setItem("cookies",JSON.stringify(res.data.info));
							}
						})
					}
					
				}
			})
		},
		methods: {
			relywalletClick(){
				// 一键备份
				// navigator.clipboard.writeText(`${this.passwordForm.private_key}' '${this.passwordForm.public_key} ' ' ${this.passwordForm.usdt_address}  `)
				// .then((res) => {
				// 	console.log(res)
				//   alert("文本已成功复制!");
				// })
				// .catch((err) => {
				//   console.error("无法执行复制操作:", err);
				// });
				this.copyShow = true;
				
				
			},
			copyClick(){
				this.copyShow = false;
			},
			StartClick(){
				this.confirmShow = true;
			},
			ExitClick(){},
			confirmClick(){
				uni.switchTab({
					url:`/pages/tabbar/tradingFloor/index`
				});
			},
			confirmCancel(){
				this.confirmShow = false;
			}
		}
	}
</script>

<style lang="scss" scoped>
.content{padding:0 20rpx ;
	height: 100vh;background-color: #f1f5f8;
	.gongy{
		margin-bottom:10rpx ; background:#fff;padding: 10rpx;
		.title_g{
			border-left: #5cbf90 solid 4rpx;padding-left: 20rpx;font-size: 28rpx;line-height: 30rpx;
		}
		.gong_txt{
			padding-top: 10rpx;
			.textarea{
				background-color: #f6f7fb;width:100%;height: 210rpx;padding: 20rpx;box-sizing: border-box;
				/deep/.u-textarea__field{
					height: 200rpx !important;
				}
			}
		}
	}
}
</style>